<!DOCTYPE html>
<html lang="en-us">

<head>
    <title>免费券使用情况--医院级详情</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" href="favicon.ico" />
    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/font-awesome.min.css" rel="stylesheet" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap/bootstrap.min.js"></script>
    <script src="js/bootstrap/bootstrap-table.min.js"></script>
    <script src="js/bootstrap/bootstrap-table-zh-CN.min.js"></script>
    <!--[if lt IE 9]>
    <script src="js/bootstrap/html5shiv.min.js"></script>
    <script src="js/bootstrap/respond.min.js"></script>
    <![endif]-->
    <!--页面加载进度条-->
    <link href="css/pace/dataurl.css" rel="stylesheet" />
    <!-- 民生免费券列表页面样式-->
    <link href="css/couponReview.css" rel="stylesheet" />

    <script src="js/pace/pace.min.js"></script>
    <script src="js/jquery.scrolltopcontrol/scrolltopcontrol.js" type="text/javascript"></script>
    <script src="js/jquery.extend.js" type="text/javascript"></script>
    <script src="js/default.js" type="text/javascript"></script>
    <script src="js/jqueryrotate.js" type="text/javascript"></script>
    <script src="js/fileServer.js"></script>
    <!-- 下拉菜单 -->
    <link href="./css/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <script src="./js/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="./js/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>
    <script src="./js/bootstrap-select/bootstrap-select-custom.js"></script>
    <!-- artTemplate 模板引擎 -->
    <script src="js/template-web.js" type="text/javascript"></script>
    <!-- excel导出操作-->
    <script src="js/exportTable.js"></script>


</head>

<body>

<div class="maincontent row" style=" overflow: scroll !important;">
    <!--我是主要内容-->
    <div class="panel panel-default">
        <div class="panel-heading">
            查询条件
        </div>
        <div class="panel-body form-group" style="margin-bottom:0px; position:relative;">
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">姓名：</label>
                    <input type="text" placeholder="请输入姓名" class="form-control value" id="search-name" />
                </div>
                <div class="params-item">
                    <label class="control-label">领取开始时间：</label>
                    <input type="date" class="form-control value" id="search-start-time" />
                </div>
                <div class="params-item">
                    <label class="control-label">使用开始时间：</label>
                    <input type="date" class="form-control value" id="search-usedStartTime" />
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">区/县：</label>
                    <select name="search-country" id="search-country" class="form-control value"></select>
                </div>
                <div class="params-item">
                    <label class="control-label">领取结束时间：</label>
                    <input type="date" class="form-control value" id="search-end-time" />
                </div>
                <div class="params-item">
                    <label class="control-label">使用结束时间：</label>
                    <input type="date" class="form-control value" id="search-usedEndTime" />
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">街道：</label>
                    <select name="search-town" id="search-town" class="form-control value"></select>
                </div>
                <div class="params-item">
                    <label class="control-label">优惠券类型：</label>
                    <select name="search-coupon" id="search-coupon" class="form-control value"></select>
                </div>
                <div class="params-item">
                    <label class="control-label">状态：</label>
                    <select type="text" class="form-control value" id="search-status">
                        <option value="2">已使用</option>
                        <option value="0">审批中</option>
                        <option value="1">审批通过</option>
                        <option value="-1">未审批通过</option>
                        <option value="3">已绑定的</option>
                    </select>
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">身份证号码：</label>
                    <input type="text" placeholder="请输入身份证号码" class="form-control value" id="search-idcard" />
                </div>
                <div class="params-item">
                    <label class="control-label">采血机构：</label>
                    <select id="search-customer" class="selectpicker form-control value" data-live-search="true" data-max-options="1">
                    </select>
                </div>
                <div class="params-item">
                    <label class="control-label">检测机构：</label>
                    <select id="search-inspectionAgencyName" class="form-control value">
                    </select>
                </div>
                <div class="params-item" style="display: none">
                    <label class="control-label">收费类型：</label>
                    <select name="isCharge" id="isCharge" class="form-control value">
                        <option value="1">免费</option>
                        <option value="2">自费</option>
                    </select>
                </div>
            </div>
            <button class="btn btn-primary" id="search-btn">查询</button>
        </div>
    </div>
    <p class="statisticalTime" style="font-size: 24px;text-align: center"></p>
    <table id="mytab" class="table table-hover"></table>
    <div id="toolbar" class="btn-group pull-right" style="margin-right: 20px;">
        <button id="btn_edit" type="button" class="btn btn-default" style="display: none; border-radius: 0">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
        </button>
        <button id="btn_delete" type="button" class="btn btn-default" style="display: none;">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
        </button>
        <div style="display: flex;flex-direction: row; align-items: center;">
            <a href="javascript:exportTable();" class="btn btn-default" style="margin-left: 10px">导出</a>
            <div id="fountainTextG">
                <div id="fountainTextG_1" class="fountainTextG">导</div>
                <div id="fountainTextG_2" class="fountainTextG">出</div>
                <div id="fountainTextG_3" class="fountainTextG">中</div>
                <div id="fountainTextG_4" class="fountainTextG">.</div>
                <div id="fountainTextG_5" class="fountainTextG">.</div>
                <div id="fountainTextG_6" class="fountainTextG">.</div>
                <div id="fountainTextG_7" class="fountainTextG">请</div>
                <div id="fountainTextG_8" class="fountainTextG">稍</div>
                <div id="fountainTextG_9" class="fountainTextG">后</div>
            </div>
        </div>
    </div>
</div>
</div>
<!-- 装要导出送检单的table -->
<div class="ghost-tables"></div>

<a href="#top" id="goTop">
    <i class="fa fa-angle-up fa-3x"></i>
</a>
<div id="id-card-photo-wrapper">
    <img alt='' id="id-card-photo" />
    <span class="glyphicon glyphicon-repeat" aria-hidden="true" id="ic-rotate"></span>
    <span class="arrow l">&lt;</span>
    <span class="arrow r">&gt;</span>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    转发
                </h4>
            </div>
            <div class="modal-body">
                转发至：
                <select name='' id="countrySelect" onchange="onCountryChange(this.value)">&nbsp;&nbsp;
                </select>
                <select name='' id="steetSelect" onchange="onSteetChange(this.value)">
                </select>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="transpond();">
                    确认
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="agreeModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    确认批量审核
                </h4>
            </div>
            <div class="modal-body">
                <div class="agree-list">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" class="btn btn-primary" style="margin-left:20px;" onclick="agree();">
                    同意
                </button>
                <button type="button" class="btn btn-primary" onclick="disAgree();">
                    不同意
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>
<script type="text/javascript" >
    //区县列表getAddrs
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: { method: 'getAddrs', parentId: 4301 },
        success: function (res) {
            var options = '<option value="">请选择</option>'
            if (res && res.code == 200) {
                (res.rows || []).forEach(countryItem => {
                    options += '<option value="' + countryItem.name + '">' + countryItem.name + '</option>';
                })
            }
            $('#search-country').html(options);
        }
    });
    //获取报表统计截止时间
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do?method=getStatisticalTime',
        success: function (res) {
            if (res && res.code == 200) {
                var time = Date.parse(res.rows);
                var date = new Date(time);
                $(".statisticalTime").text("数据统计截止时间为：" + date.pattern("yyyy-MM-dd HH:mm:ss"));
            }
        }
    });

    //优惠券类型下拉框数据
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: { method: 'getBaseCouponInfos' },
        success: function (res) {
            var options = '<option value="">请选择</option>'
            if (res && res.code == 200) {
                (res.rows || []).forEach(coupon => {
                    options += '<option value="' + coupon.type + '">' + coupon.couponName + '</option>';
                })
            }
            $('#search-coupon').html(options);
        }
    });

    $(function () {
        //街道getTown
        $('#search-country').change(function () {
            var countryStr = $(this).val();//获得区县
            $.ajax({
                method: 'POST',
                url: '/csfy/intf.do',
                data: { method: 'getTown', name: countryStr },
                success: function (res) {
                    var options = '<option value="">请选择</option>'
                    if (res && res.code == 200) {
                        (res.rows || []).forEach(countryItem => {
                            options += '<option value="' + countryItem.name + '">' + countryItem.name + '</option>';
                        })
                    }
                    $('#search-town').html(options);
                }
            });
        });
    });

    //医院列表
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: {
            method: 'getCustomers',
            addressCity: '长沙市',
        },
        success: function (res) {
            if (res && res.code == 200) {
                var customerList = res.rows || [];
                var customerOptions = '<option value="">请选择</option>';
                customerList.forEach(customer => {
                    customerOptions += '<option value="' + customer.customerCode + '">' + customer.customerName + '</option>';
                });
                $('#search-customer').html(customerOptions);
                //$("#search-customer option[value='34']").removeAttr("selected");//默认选中长沙市妇幼保健院
                $('.selectpicker').selectpicker('refresh');
            }
        }
    });
    //检测机构列表
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do?method=getyInspectionAgencyNameList',
        success: function (res) {
            if (res && res.code == 200) {
                var customerList = res.rows || [];
                var customerOptions = '<option value="">请选择</option>';
                customerList.forEach(customer => {
                    customerOptions += '<option value="' + customer.inspectionAgencyId + '">' + customer.inspectionAgencyName + '</option>';
                });
                $('#search-inspectionAgencyName').html(customerOptions);
            }
        }
    });

    var flag = false
    // 导出表格
    function exportTable() {
        var name = $("#search-name").val() || '';
        var startTime = $("#search-start-time").val() || '';
        var endTime = $("#search-end-time").val() || '';
        var status = $("#search-status").val() || '';
        var town = $("#search-town").val() || '';
        //优惠券类型
        var type = $("#search-coupon").val() || '';
        //身份证号
        var id = $("#search-idcard").val() || '';
        //区/县
        var country = $("#search-country").val() || '';
        //送检医院
        var customerCode = $("#search-customer").val() || '';
        //使用时间
        var usedStartTime = $("#search-usedStartTime").val() || '';
        var usedEndTime = $("#search-usedEndTime").val() || '';
        var sendHospitalName = $("#search-customer option:selected").text() || '';
        var inspectionAgencyName = $("#search-inspectionAgencyName option:selected").text() || '';
        if(sendHospitalName == "请选择"){
            sendHospitalName = "";
        }
        var productName = $("#productName").val() || '';
        if(productName == "请选择"){
            productName = "";
        }
        var query = {};

        if (inspectionAgencyName != '' && inspectionAgencyName != '请选择') {
            query.inspectionAgencyName = inspectionAgencyName;
        }
        if (name != '') {
            query.presonName = name;
        }
        //开始时间
        if (startTime != '') {
            query.receiveStartTime = startTime;
        }
        //结束时间
        if (endTime != '') {
            query.receiveEndTime = endTime;
        }
        if (status != '') {
            query.couponStatus = status;
        }
        if (town != '') {
            query.town = town;
        }

        if (id != '') {
            query.presonCardId = id;
        }
        //区/县
        if (country != '') {
            query.country = country;
        }
        //送检医院
        if (customerCode != '') {
            query.customerCode = customerCode;
        }
        //优惠券类型
        if (type != '') {
            query.couponBaseId = type;
        }
        //使用时间
        if (usedStartTime != '') {
            query.usedStartTime = usedStartTime;
        }
        if (usedEndTime != '') {
            query.usedEndTime = usedEndTime;
        }
        if (sendHospitalName != '') {
            query.customerName = sendHospitalName;
        }
        if (productName != '') {
            query.productName = productName;
        }
        query.isCharge = $("#isCharge").val();
        var time = new Date().getTime();
        if (!flag) {
            flag = true;
            $("#fountainTextG").show();
            $.ajax({
                method: 'POST',
                url: '/csfy/intf.do?method=getDataByCustomerName&couponStatus=2&filterType=2',
                data:query,
                success: function (res) {
                    var delay = 2000 - (new Date().getTime() - time);
                    if (delay < 0) delay = 0;
                    setTimeout(function () {
                        flag = false;
                        $("#fountainTextG").hide();
                        setTimeout(() => {
                            if (res && res.code && res.code == 200) {
                                exportHospitalAccount(res.rows);
                            }
                        }, 100)
                    }, delay);
                },
                error: function (err) {
                    flag = false;
                    $("#fountainTextG").hide();
                }
            })
        }
    }

    //退出登录
    function logout() {
        $.ajax({
            url: '/csfy/dologout.do',
            method: 'POST',
            success: function (res) {
                if (JSON.parse(res).code == 200) {
                    window.location.href = "/csfy/index.do"
                }
            }
        })
    }
    //TODO 获取当前登录用户所在的省市区 start
    //设置街道
    function onSteetChange(parentId) {
        town = $("#steetSelect option[value='" + parentId + "']").text();
    }
    //设置地区
    function onCountryChange(parentId) {
        country = $("#countrySelect option[value='" + parentId + "']").text();
        $.ajax({
            method: 'POST',
            url: '/csfy/intf.do',
            data: {
                method: 'getAddrs',
                parentId,
            },
            success: (res) => {
                if (res.code == 200 && res.rows) {
                    var steetList = '';
                    town = '';
                    res.rows.map((item, index) => {
                        if (index == 0) {
                            town = item.name;
                        }
                        steetList += '<option value="' + item.code + '">' + item.name + '</option>'
                    })
                    $("#steetSelect").html(steetList);
                }
            }
        });
    }
    //获取当前登录用户所在的省市区 end

    var idCard = '';//身份证
    var town = '';//街道
    var country = '';//地区

    //TODO 确定转发
    function transpond() {
        $.ajax({
            method: 'POST',
            data: {
                method: 'savePresonInfo',
                id: idCard,
                town: town,
                country: country
            },
            url: '/csfy/intf.do',
            success: (res) => {
                if (res.code == 200) {
                    $('#search-btn').trigger("click");
                    alert('转发成功！');
                    $('#myModal').modal('hide');
                }
            }
        })
    }
    $("body").click(function () {
        $("#id-card-photo-wrapper").hide(300);
        angle = 0;
        $("#id-card-photo").rotate(0);
    })
    Date.prototype.pattern = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
            "H+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        var week = {
            "0": "/u65e5",
            "1": "/u4e00",
            "2": "/u4e8c",
            "3": "/u4e09",
            "4": "/u56db",
            "5": "/u4e94",
            "6": "/u516d"
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        if (/(E+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : '') + week[this.getDay() + '']);
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(('' + o[k]).length)));
            }
        }
        return fmt;
    }
    //根据窗口调整表格高度
    $(window).resize(function () {
        $('#mytab').bootstrapTable('resetView', {
            height: tableHeight()
        })
    })
    //生成用户数据
    $('#mytab').bootstrapTable({
        method: 'POST',
        contentType: "application/x-www-form-urlencoded",//必须要有！！！！
        url: "/csfy/intf.do?method=getDataByCustomerName&couponStatus=2&filterType=2",//要请求数据的文件路径
        height: tableHeight(),//高度调整
        toolbar: '#toolbar',//指定工具栏
        striped: true, //是否显示行间隔色
        dataField: "rows",//bootstrap table 可以前端分页也可以后端分页，这里
        //我们使用的是后端分页，后端分页时需返回含有total：总记录数,这个键值好像是固定的
        //rows： 记录集合 键值可以修改  dataField 自己定义成自己想要的就好
        pageNumber: 1, //初始化加载第一页，默认第一页
        pagination: true,//是否分页
        queryParamsType: 'limit',//查询参数组织方式
        queryParams: queryParams,//请求服务器时所传的参数
        sidePagination: 'server',//指定服务器端分页
        pageSize: 10,//单页记录数
        pageList: [5, 10, 20, 30],//分页步进值
        showRefresh: true,//刷新按钮
        // showColumns: true,
        clickToSelect: true,//是否启用点击选中行
        toolbarAlign: 'left', //工具栏对齐方式
        buttonsAlign: 'left',//按钮对齐方式
        toolbar: '#toolbar',//指定工作栏
        columns: [
            //                {
            //                    title: '全选',
            //                    field: 'select',
            //                    //复选框
            //                    checkbox: false,
            //                    width: 25,
            //                    align: 'center',
            //                    valign: 'middle'
            //                },
            {
                title: '姓名',
                field: 'presonName'
            },
            {
                title: '身份证号',
                formatter: formatCardId
            },
            {
                title: '手机号码',
                field: 'mobile'
            },
            {
                title: '免费券码',
                field: 'couponCode'
            },
            {
                title: '采血机构',
                field: 'customerName'
            },
            {
                title: '检测机构',
                field: 'inspectionAgencyName'
            },
            {
                title: '领取日期',
//                    field: 'createTime',
                field: 'receiveTime',
                //列数据格式化
                formatter: formatDate
            },
            {
                title: '使用时间',
                field: 'usedTime',
                formatter: formatDate
            },
            {
                title: '区/县',
                //列数据格式化
                formatter: formatCountry
            },
            {
                title: '街道',
                //列数据格式化
                formatter: formatTown
            },
            {
                title: '免费券类型',
                field: 'couponBaseName',
                width: 120
            }
        ],
        locale: 'zh-CN',//中文支持,
        responseHandler: function (res) {
            //在ajax获取到数据，渲染表格之前，修改数据源
            return res;
        },
        onRefresh: function (params) {
            if (params && params.query) {
                return false;
            }
            $("#search-name").val('');
            $("#search-start-time").val('');
            $("#search-end-time").val('');
            $("#search-status").val('');
            $("#search-town").val('');
            $("#search-coupon").val('');
            $("#search-idcard").val('');
            $("#search-country").val('');
            $("#search-customer").val('');
            $("#search-inspectionAgencyName").val('');
            $("#search-usedStartTime").val('');
            $("#search-usedEndTime").val('');
        }
    });
    function toDetail(id) {
        window.location.href = "/csfy/static/manage-sys/coupon-detail.html?id=" + id
    }
    //三个参数，value代表该列的值
    function formatStatus(value, row, index) {
        var text = ''
        if (value == 1) {
            text = '审批通过';
        } else if (value == 0) {
            text = '审批中';
        } else if (value == -1) {
            text = '未审批通过';
        } else if (value == 2) {
            text = '已使用';
        } else if (value == 3) {
            text = '已绑定';
        }
        return `<span style="color: rgba(0,0,0,.45);">${text}</span>`;
    }
    //优惠券类型
    function formatCouponInfos(value, row, index) {
        var text = '-';
        var divHtml = '';
        for (var i = 0; i < row.couponInfos.length; i++) {
            if (row.couponInfos[i].type == 1) {
                text = "耳聋基因检测";
            } else if (row.couponInfos[i].type == 2) {
                text = "NIPT检测";
            } else if (row.couponInfos[i].type == 3) {
                text = "HPV检测";
            } else if (row.couponInfos[i].type == 4) {
                text = "产前血清学筛查";
            } else if (row.couponInfos[i].type == 5) {
                text = "新生儿疾病筛查";
            } else if (row.couponInfos[i].type == 6) {
                text = "地贫筛查";
            }
            divHtml += '<span style="color: rgba(0,0,0,.45);">' + text + '</span><br>';
        }
        return divHtml;
    }
    function formatCountry(value, row) {
        return row.country;
    }
    function formatTown(value, row) {
        return row.town;
    }
    //三个参数，value代表该列的值
    function formatName(value, row, index) {
        return '<a class="link" style="color:#333;cursor: default;text-decoration: none;" href="javascript:void(0)">' + value + '</a>';
    }
    //三个参数，value代表该列的值
    function operateFormatter(value, row, index) {
        return '<a style="color:#333;cursor: default;text-decoration: none;" href="javascript:void(0)">转发</a>'
    }
    function setIdCard(id) {
        idCard = id;
        $('#myModal').modal('show')
    }
    //三个参数，value代表该列的值
    function formatAddress(value, row, index) {
        return (row.city || '') + (row.country || '') + (row.town || '');
    }
    //三个参数，value代表该列的值
    function formatDate(value, row, index) {
        if(value == undefined){
            return;
        }else {
            var time = Date.parse(value);
            var date = new Date(time);
            return date.pattern("yyyy-MM-dd HH:mm:ss");
        }
    }
    function formatCardId(value, row, index) {
        var cardId = row.presonCardId + '-';
        return cardId
    }
    //三个参数，value代表该列的值
    function formatPersonType(value, row, index) {
        //优惠类型
        var type = parseInt(value);
        var text = '其他免费类型';
        if (isNaN(type)) {
        } else {
            if (type === 1) {
                text = '本人为长沙户口';
            } else if (type === 2) {
                text = '配偶为长沙户口';
            } else if (type === 3) {
                text = '长沙居住证';
            } else if (type === 4) {
                text = '军人及军人配偶';
            }
        }
        return '<span style="color: rgba(0,0,0,.45);">' + text + '</span>';
    }
    function toSeeIdCardPhoto(...photoUrl) {
        var newUrls = [...photoUrl].filter(url => url.indexOf('.') != -1).map(url => url)
        var ele = $("#id-card-photo")[0]
        ele.photoUrls = newUrls
        ele.photoIndex = 0
        $("#id-card-photo").attr('src', ele.photoUrls[ele.photoIndex]);
        $("#id-card-photo-wrapper").show(300);
    }
    //三个参数，value代表该列的值
    function formatPhoto(value, row, index) {
        return `<a class="link" href="javascript:toSeeIdCardPhoto('${row.cardFrontImgUrl}','${row.marriageImgUrl}','${row.cardMateImgUrl}','${row.officerImgUrl}','${row.residencePermitImgUrl}','${row.familyRegisterImgUrl}');">查看</a>`;
    }
    var countryTags = ['区', '市', '县']
    var townTags = ['街道', '镇', '乡']
    //请求服务数据时所传参数
    function queryParams(params) {
        var param = new Object();
        var name = $("#search-name").val();
        var sendHospitalName = $("#search-customer option:selected").text();
        if (sendHospitalName != '' && sendHospitalName != '请选择') {
            param.customerName = sendHospitalName;
        }
        var inspectionAgencyName = $("#search-inspectionAgencyName option:selected").text();
        if (inspectionAgencyName != '' && inspectionAgencyName != '请选择') {
            param.inspectionAgencyName = inspectionAgencyName;
        }
        var productName = $("#productName").val();
        if (productName != null && productName != '' && productName != '请选择') {
            param.productName = productName;
        }
        if (name != '') {
            param.presonName = name;
        }
        var couponType = $("#search-coupon").val();

        if (couponType != null && couponType != '') {
            param.couponBaseId = couponType;
        }
        var status = $("#search-status").val();
        if (status != null && status != '') {
            param.couponStatus = status;
        }
        var startTime = $("#search-start-time").val();
        if (startTime != '') {
            param.receiveStartTime = startTime;
        }
        var endTime = $("#search-end-time").val();
        if (endTime != '') {
            param.receiveEndTime = endTime;
        }
        var town = $("#search-town").val();
        if (town != null && town != '') {
            param.town = town;
        }
        var id = $("#search-idcard").val();
        if (id != '') {
            param.presonCardId = id;
        }
        var country = $("#search-country").val();
        if (country != null && country != '') {
            param.country = country;
        }
        var usedStartTime = $("#search-usedStartTime").val();
        if (usedStartTime != '') {
            param.usedStartTime = usedStartTime;
        }
        var usedEndTime = $("#search-usedEndTime").val();
        if (usedEndTime != '') {
            param.usedEndTime = usedEndTime;
        }
        param.isCharge = $("#isCharge").val();
        param.rows = params.limit;
        param.page = (params.offset + params.limit) / params.limit;

        return param;

        //
        //            return {
        //                //每页多少条数据
        //                rows: params.limit,
        //                //请求第几页
        //                page: (params.offset + params.limit) / params.limit,
        //            }
    }

    //查询按钮事件
    $('#search-btn').click(function () {
        var name = $("#search-name").val() || '';
        var startTime = $("#search-start-time").val() || '';
        var endTime = $("#search-end-time").val() || '';
        var status = $("#search-status").val() || '';
        var town = $("#search-town").val() || '';
        //优惠券类型
        var type = $("#search-coupon").val() || '';
        //身份证号
        var id = $("#search-idcard").val() || '';
        //区/县
        var country = $("#search-country").val() || '';
        //送检医院
        var customerCode = $("#search-customer").val() || '';
        //使用时间
        var usedStartTime = $("#search-usedStartTime").val() || '';
        var usedEndTime = $("#search-usedEndTime").val() || '';
        var sendHospitalName = $("#search-customer option:selected").text() || '';
        var inspectionAgencyName = $("#search-inspectionAgencyName option:selected").text() || '';
        if(sendHospitalName == "请选择"){
            sendHospitalName = "";
        }
        var productName = $("#productName").val() || '';
        if(productName == "请选择"){
            productName = "";
        }
        var query = {};

        if (inspectionAgencyName != '' && inspectionAgencyName != '请选择') {
            query.inspectionAgencyName = inspectionAgencyName;
        }
        if (name != '') {
            query.presonName = name;
        }
        //开始时间
        if (startTime != '') {
            query.receiveStartTime = startTime;
        }
        //结束时间
        if (endTime != '') {
            query.receiveEndTime = endTime;
        }
        if (status != '') {
            query.couponStatus = status;
        }
        if (town != '') {
            query.town = town;
        }

        if (id != '') {
            query.presonCardId = id;
        }
        //区/县
        if (country != '') {
            query.country = country;
        }
        //送检医院
        if (customerCode != '') {
            query.customerCode = customerCode;
        }
        //优惠券类型
        if (type != '') {
            query.couponBaseId = type;
        }
        //使用时间
        if (usedStartTime != '') {
            query.usedStartTime = usedStartTime;
        }
        if (usedEndTime != '') {
            query.usedEndTime = usedEndTime;
        }
        if (sendHospitalName != '') {
            query.customerName = sendHospitalName;
        }
        if (productName != '') {
            query.productName = productName;
        }
        query.isCharge = $("#isCharge").val();
        $('#mytab').bootstrapTable('refresh', { url: '/csfy/intf.do?method=getDataByCustomerName&filterType=2', query });
    })
    //tableHeight函数
    function tableHeight() {
        //可以根据自己页面情况进行调整
        return $(window).height() - 280;
    }
    $("#btn_add").click(function () {
        //TODO
        window.location.href = "/csfy/static/manage-sys/coupon-apply.html"
    });
    //批量审批，身份证列表
    var idList = [];
    function agreeList() {
        var rows = $("#mytab").bootstrapTable('getSelections');
        if (!rows || rows.length === 0) {
            alert('未选中操作的行');
        } else {
            var agreeList = '';
            idList.length = 0;
            rows.map(item => {
                idList.push(item.id);
                if (item.couponInfos && item.couponInfos.length && item.couponInfos.length > 0) {
                    var couponList = [];
                    item.couponInfos.forEach(couponItem => couponList.push(couponItem.couponName));
                    agreeList += '<p class="agree-item">' + (item.name + '，' + item.id + '，' + item.address + '，免费券：' + couponList.join("、")) + '</p>';
                } else {
                    agreeList += '<p class="agree-item">' + (item.name + '，' + item.id + '，' + item.address + '，免费券：无') + '</p>';
                }
            });
            $(".agree-list").html(agreeList);
            $('#agreeModel').modal('show');
        }
    }
    var angle = 0;
    $("#ic-rotate").bind("click", function (event) {
        event.stopPropagation();
        $("#id-card-photo").rotate({
            angle: angle,
            animateTo: angle + 90,
            duration: 300,
            callback: function () { angle += 90 }
        });
    });

    //上一张
    $("#id-card-photo-wrapper .arrow.l").bind("click", function (event) {
        event.stopPropagation();
        var ele = $("#id-card-photo")
        ele = ele ? ele[0] : undefined
        if (ele) {
            var photoUrls = ele.photoUrls || []
            var index = ele.photoIndex
            if (index > 0) {
                ele.photoIndex = index - 1
                $("#id-card-photo").attr('src', photoUrls[index - 1]);
            }
        }
    });
    //下一张
    $("#id-card-photo-wrapper .arrow.r").bind("click", function (event) {
        event.stopPropagation();
        var ele = $("#id-card-photo")
        ele = ele ? ele[0] : undefined
        if (ele) {
            var photoUrls = ele.photoUrls || []
            var index = ele.photoIndex
            if (photoUrls.length > 0 && index + 1 < photoUrls.length) {
                ele.photoIndex = index + 1
                $("#id-card-photo").attr('src', photoUrls[index + 1]);
            }
        }
    });
    //同意——批量审批
    function agree() {
        $("#agreeModel").modal('hide');

        var promise = new Promise(function (resolve, reject) {
            var index = 0;
            var success = true;
            idList.map(id => {
                $.ajax({
                    url: '/csfy/intf.do',
                    method: 'POST',
                    data: { method: 'savePresonInfo', id: id, status: '1' },
                    success: function (res) {
                        success = res.code == 200;
                        index++;
                        if (index == idList.length) {
                            if (success) {
                                resolve('操作成功');
                            } else {
                                reject('操作失败');
                            }
                        }
                    }, error: function (msg) {
                        index++;
                        if (index == idList.length) {
                            reject('操作失败');
                        }
                    }
                })
            });
        });

        promise.then(function (value) {
            alert(value);
        }, function (value) {
            alert(value);
        });
    }
    //不同意——批量审批
    function disAgree() {
        $("#agreeModel").modal('hide');

        var promise = new Promise(function (resolve, reject) {
            var index = 0;
            var success = true;
            idList.map(id => {
                $.ajax({
                    url: '/csfy/intf.do',
                    method: 'POST',
                    data: { method: 'savePresonInfo', id: id, status: '-1' },
                    success: function (res) {
                        success = res.code == 200;
                        index++;
                        if (index == idList.length) {
                            if (success) {
                                resolve('操作成功');
                            } else {
                                reject('操作失败');
                            }
                        }
                    }, error: function (msg) {
                        index++;
                        if (index == idList.length) {
                            reject('操作失败');
                        }
                    }
                })
            });
        });

        promise.then(function (value) {
            alert(value);
        }, function (value) {
            alert(value);
        });
    }


</script>

<!-- 要导出的送检单table模板 -->
<script id="table" type="text/html">
    <table border="1" class="tables">
        <tr>
            {{each ths item i}}
            <th>{{item.fieldValue}}</th>
            {{/each}}
        </tr>
        {{each trs item i}}
        <tr>
            {{each item value i}}
            <td>{{value}}</td>
            {{/each}}
        </tr>
        {{/each}}
    </table>
</script>
</body>

</html>